AddModuleConfiguration
此函式允許使用者透過覆寫 EtherCAT 自動配置來新增無法被自動配置偵測到的裝置。
此函式有兩個用途:
- 新增無法透過自動配置偵測到的裝置,例如 IO-Link、部份 CANopen 以及連接至耦合器的裝置。
- 覆寫 EtherCAT 自動配置。欲覆寫自動配置,需在裝置連接到 KINGSTAR 前使用此函式。
語法
KsError AddModuleConfiguration(
int SlaveId,
int ModuleId,
KsConfigurationType ConfigurationType,
VOID* Configuration
);
參數
SlaveId:從站陣列的索引。當 EtherCAT 從站裝置啟動時,此索引具有與 SlaveId 相同的值,該值對應於從站裝置在網路中的位置。請注意,在 EtherCAT 進入運行 (Op) 狀態後,加入或移除網路上的任何從站裝置將改變各裝置在網路中的位置 (SlaveId)。儘管如此,從站的索引將保持不變。新增的裝置將排列在陣列的末端。對於更改後的所有從站,索引和 SlaveId 將不再匹配。上述行為模式僅適用於實體裝置;不適用於模擬裝置。詳細資訊請參閱 EnableHotConnect 中的使用案例。
ModuleId:(連接至耦合器的裝置)的模組 ID,此可以是槽 ID、連接埠 ID 或從站 ID。
ConfigurationType:裝置與耦合器間的連接類型。請見 KsConfigurationType 類型。
Configuration:配置結構的指標,此取決於使用的通訊協定。例如,若協定為 IO-Link,則配置為 IoLinkSetting 結構。
回傳值
如果此函式執行成功,會回傳 errNoError
,否則會傳回錯誤碼。如需更多有關錯誤碼的資訊,請參閱 KsError 清單。
備註
可用的 EtherCAT 狀態
ecatOffline
範例
複製
// configIoLink
IoLinkSetting IoLink = {
17, // IO-Link specification: Version 1.1
0, // SPDU
3, // Control
32, // Input length
0 // Output length
};
nRet = AddModuleConfiguration(
2, // EthercatSlaveID
0, // LinkedDeviceID
configIoLink, // Protocol
&IoLink // Settings
);
// configCANopen
CanOpenSetting CanOpen = { 0 };
CanOpen.RxPdoCount = 4;
CanOpen.RxPdos[0] = { TRUE, 16, 0x1800, 0xFF };
CanOpen.RxPdos[1] = { FALSE, 48, 0x1801, 0xFF };
CanOpen.RxPdos[2] = { FALSE, 48, 0x1802, 0xFF };
CanOpen.RxPdos[3] = { FALSE, 0, 0x1803, 0xFF };
CanOpen.TxPdoCount = 4;
CanOpen.TxPdos[0] = { TRUE, 16, 0x1400, 0xFF };
CanOpen.TxPdos[1] = { FALSE, 48, 0x1401, 0xFF };
CanOpen.TxPdos[2] = { FALSE, 48, 0x1402, 0xFF };
CanOpen.TxPdos[3] = { FALSE, 0, 0x1403, 0xFF };
CanOpen.SdoCommandCount = 1;
CanOpen.SdoCommands[0].Index = 0x6060;
CanOpen.SdoCommands[0].SubIndex = 0;
CanOpen.SdoCommands[0].Length = 1;
CanOpen.SdoCommands[0].Data[0] = 0x1;
nRet = AddModuleConfiguration(
1, // EthercatSlaveID
0x70, // LinkedDeviceID, it is CANopen device's node ID for CANopen protocol
configCANopen, // Protocol
&CanOpen // Settings
);
// configEsi
AddModuleConfiguration(3, (int)strlen("Sanyodenki RS2 special"), configEsi, "Sanyodenki RS2 special");
使用需求
RT | Win32 | |
---|---|---|
最低支援版本 | 4.0 | 4.0 |
標頭檔 | ksapi.h | ksapi.h |
程式庫 | KsApi_Rtss.lib | KsApi.lib |
參見